// pc.js - 修正版
import { getJwt } from "@/api/jwt.js"

// PC端路由配置数组
const pcRoutes = [
    {
        name: "总页面",
        path: "/main",
        component: () => import("@/components/view/Main.vue"),
        children: [{
            name: "客户管理页面",
            path: "/main/user",
            component: () => import("@/components/view/User.vue")
        }, {
            name: "数据看板页面",
            path: "/main/dashboard",
            component: () => import("@/components/view/TotalData.vue")
        }, {
            name: "宠物管理页面",
            path: "/main/pet",
            component: () => import("@/components/view/Pet.vue")
        }, {
            name: "服务项目管理页面",
            path: "/main/orders",
            component: () => import("@/components/view/Order.vue")
        }, {
            name: "预约管理页面",
            path: "/main/appointment",
            component: () => import("@/components/view/Appointment.vue")
        }]
    }, {
        name: "index",
        path: "/",
        redirect: "/main"
    }, {
        name: "登陆页面",
        path: "/login",
        component: () => import("@/components/view/Login.vue")
    }
]

// PC端路由守卫
export const pcBeforeEach = (to, from, next) => {
    let jwt = getJwt();
    if (jwt) {
        if (to.name === "登陆页面") {
            next("/main");
        } else {
            next();
        }
    } else {
        if (to.name === "登陆页面") {
            next();
        } else {
            next("/login");
        }
    }
}

// 导出路由数组，不是router实例
export default pcRoutes